package com.hopes.bizz.risk.control.vo;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.*;
import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
import com.alibaba.excel.enums.poi.VerticalAlignmentEnum;
import com.hopes.bizz.common.core.annotation.ExcelDictValidate;
import com.hopes.bizz.common.core.annotation.ExcelNotNull;
import com.hopes.bizz.common.core.util.StringUtils;
import com.hopes.bizz.risk.common.constant.enums.RiskSysDictEnum;
import com.hopes.bizz.risk.control.entity.RiskMeasureTaskEntity;
import com.hopes.boss.admin.api.resolver.enums.AdminDictEnum;
import com.hopes.boss.common.entity.ExcelDTO;
import lombok.*;

import java.io.Serializable;

/**
 * @author yumr
 * @Description 风险管控清单
 * @time 2023/7/24 14:15
 */


@Data
@Builder
@ColumnWidth(20)
@NoArgsConstructor
@AllArgsConstructor
@HeadRowHeight(30)
@ContentRowHeight(20)
@EqualsAndHashCode(callSuper = true)
@HeadStyle( horizontalAlignment = HorizontalAlignmentEnum.CENTER, verticalAlignment = VerticalAlignmentEnum.CENTER)
@ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.LEFT, verticalAlignment = VerticalAlignmentEnum.CENTER)
public class RiskIdentifyExcelVO extends ExcelDTO implements Serializable {

    private static final long serialVersionUID = -8838604950205456711L;

    @ExcelIgnore
    private Long id;

    @ExcelProperty("序号")
    private String index;

    @ExcelNotNull(message = "作业步骤不可为空")
    @ExcelProperty({"第一步：风险事件", "作业步骤"})
    private String jobStep;

    @ExcelNotNull(message = "风险事件不可为空")
    @ExcelProperty({"第一步：风险事件", "风险事件"})
    private String eventName;

    @ExcelNotNull(message = "主要后果不可为空")
    @ExcelProperty({"第一步：风险事件", "主要后果"})
    private String majorConsequenceDesc;

    @ExcelNotNull(message = "固有风险等级不可为空")
    @ExcelProperty({"第二步：评估固有风险", "固有风险等级"})
    @ExcelDictValidate(enumResolver = "risk_level")
    private String riskLevelStr;

    @ExcelNotNull(message = "固有风险描述不可为空")
    @ExcelProperty({"第二步：评估固有风险", "固有风险描述"})
    private String riskDesc;

    @ExcelIgnore
    private Long controlMeasureId; // 管控措施Id

    @ExcelProperty({"第三步：管控措施", "管控层级"})
    @ExcelDictValidate(enumResolver = "risk_control_level")
    private String controlLevelStr;

    @ExcelNotNull(message = "管控措施描述不可为空")
    @ExcelProperty({"第三步：管控措施", "管控措施描述"})
    private String riskMeasureDesc;

    @ExcelNotNull(message = "管控排查内容不可为空")
    @ExcelProperty({"第三步：管控措施", "管控排查内容"})
    private String checkContent;

    @ExcelNotNull(message = "管控措施分类1不可为空")
    @ExcelProperty({"第三步：管控措施", "管控措施分类1"})
    @ExcelDictValidate(enumResolver = "risk_control_classify")
    private String classify1Str;

    @ExcelNotNull(message = "管控措施分类2不可为空")
    @ExcelProperty({"第三步：管控措施", "措施分类2"})
    @ExcelDictValidate(enumResolver = "risk_control_classify")
    private String classify2Str;

    @ExcelProperty({"第三步：管控措施", "措施分类3"})
    private String classify3;

    @ExcelProperty({"第三步：管控措施", "相关法规标准"})
    private String lawDesc;

    @ExcelIgnore
    private Long taskCheckContentId;  // 隐患排查任务Id

    @ExcelProperty({"第四步：管控任务", "隐患排查内容"})
    private String taskCheckContent;

    @ExcelIgnore
    private Long riskControlTaskId; // 任务Id

    @ExcelProperty({"第四步：管控任务", "任务分级"})
    @ExcelDictValidate(enumResolver = "risk_control_level")
    private String taskControlLevelStr;

    @ExcelProperty({"第四步：管控任务", "责任人"})
    @ExcelDictValidate(enumResolver = "sys_user", multiple = true)
    private String responsibleUserIdsStr;

    @ExcelProperty({"第四步：管控任务", "周期"})
    private String checkCycle;

    @ExcelProperty({"第四步：管控任务", "单位"})
    @ExcelDictValidate(enumResolver = "check_cycle_type")
    private String checkCycleTypeStr;

    @ExcelProperty({"第四步：管控任务", "任务类型"})
    private String workTypeStr;

    @ExcelProperty({"第四步：管控任务", "包保任务对应项"})
    private String taskNumStr;

    @ExcelProperty({"第五步：评估现状风险", "现状风险等级"})
    @ExcelDictValidate(enumResolver = "risk_level")
    private String afterRiskLevelStr;

    @ExcelProperty({"第五步：评估现状风险", "现状风险描述"})
    private String afterRiskDesc;

    @ExcelIgnore
    private int rowCount;
    @ExcelIgnore
    private Long riskUnitId;
    @ExcelIgnore
    private Long riskEventId;   // 风险事件Id

    public RiskIdentifyExcelVO(RiskControlMeasureVO controlMeasureVO, RiskUnitEventVO riskUnitEventVO,
                             RiskMeasureTaskConfigVO riskMeasureTaskConfigVO, RiskMeasureTaskEntity riskMeasureTask) {
        if (null != controlMeasureVO) {
            this.controlMeasureId = controlMeasureVO.getId();
            this.controlLevelStr = controlMeasureVO.getControlLevelStr();
            this.riskMeasureDesc = controlMeasureVO.getRiskMeasureDesc();
            this.checkContent = controlMeasureVO.getCheckContent();
            this.classify1Str = controlMeasureVO.getClassify1Str();
            this.classify2Str = controlMeasureVO.getClassify2Str();
            this.classify3 = controlMeasureVO.getClassify3();
            this.lawDesc = controlMeasureVO.getLawDesc();
        }
        // 获取风险事件
        if (null != riskUnitEventVO) {
            this.riskEventId = riskUnitEventVO.getId();
            this.jobStep = riskUnitEventVO.getJobStep();
            this.eventName = riskUnitEventVO.getEventName();
            this.majorConsequenceDesc = riskUnitEventVO.getMajorConsequenceDesc();
            this.riskLevelStr = riskUnitEventVO.getRiskLevelStr();
            this.riskDesc = riskUnitEventVO.getRiskDesc();
            this.afterRiskLevelStr = riskUnitEventVO.getAfterRiskLevelStr();
            this.afterRiskDesc = riskUnitEventVO.getAfterRiskDesc();
        }
        // 管控任务
        if (null != riskMeasureTaskConfigVO) {
            this.taskCheckContentId = riskMeasureTaskConfigVO.getId();
            this.taskCheckContent = riskMeasureTaskConfigVO.getCheckContent();
        }
        if (null != riskMeasureTask) {
            this.riskControlTaskId = riskMeasureTask.getId();
            this.taskControlLevelStr = riskMeasureTask.getControlLevelStr();
            this.checkCycle = String.valueOf(riskMeasureTask.getCheckCycle());
            this.checkCycleTypeStr = riskMeasureTask.getCheckCycleTypeStr();
            this.workTypeStr = riskMeasureTask.getWorkTypeStr();
            this.taskNumStr = riskMeasureTask.getTaskNumStr();
        }
    }

    public boolean validate() {
        return StringUtils.isNotEmpty(jobStep) && StringUtils.isNotEmpty(eventName)
                && StringUtils.isNotEmpty(majorConsequenceDesc) && StringUtils.isNotEmpty(riskLevelStr)
                && StringUtils.isNotEmpty(riskDesc) && StringUtils.isNotEmpty(checkCycleTypeStr)
                && StringUtils.isNotEmpty(riskMeasureDesc) && StringUtils.isNotEmpty(checkContent)
                && StringUtils.isNotEmpty(classify1Str) && StringUtils.isNotEmpty(classify2Str);
    }
}
